package com.shz.controller;


import com.shz.pojo.Blog;
import com.shz.pojo.Category;
import com.shz.pojo.TbDish;
import com.shz.pojo.TbDishFlavor;
import com.shz.service.CategoryService;
import com.shz.service.TbDishFlavorService;
import com.shz.service.TbDishService;
import com.shz.utils.UserUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 菜品管理 前端控制器
 * </p>
 *
 * @author shz
 * @since 2024-07-29
 */
@Api(tags = "菜品模块")

@RestController
@RequestMapping("/tb-dish")
public class TbDishController {
    @Resource
    TbDishService tbDishService;
    @Resource
    CategoryService categoryService;
    @Resource
    TbDishFlavorService flavorService;

    @ApiOperation(value = "获取该基地所有分类及其分类下所有菜品")
    @ApiImplicitParam(name = "baseId", value = "基地id", required = true)
    @GetMapping("/getPlaceFood/{baseId}")
    public Object getPlaceFood(@PathVariable Integer baseId){
        List<Category> categories = categoryService.query().eq("base_id", baseId).list();
        for (Category category : categories) {
            List<TbDish> list = tbDishService.query().eq("category_id", category.getId()).list();
            category.setDishes(list);
        }
        return categories;

    }
    @ApiOperation(value = "该菜品可选择的口味列表")
    @ApiImplicitParam(name = "foodId", value = "菜品id", required = true)

    @GetMapping("/getFoodFlavor/{foodId}")
    public List<TbDishFlavor> getFoodFlavor(@PathVariable Integer foodId){
       return  flavorService.query().eq("dish_id", foodId).list();
    }
 }

